Skip to content

Fix Protocol.UndefinedError when composite casts merge struct results - #707

Closed
MajdSehwail wants to merge 1 commit into
open-api-spex:masterfrom
MajdSehwail:fix/all-of-merge-struct-values
Closed

Fix Protocol.UndefinedError when composite casts merge struct results#707
MajdSehwail wants to merge 1 commit into
open-api-spex:masterfrom
MajdSehwail:fix/all-of-merge-struct-values

Conversation

@MajdSehwail

Copy link
Copy Markdown

Fixes #705.

Cast.Utils.merge_maps/2 now demotes struct arguments to plain maps before merging. Cast.OneOf (and the discriminator path) rebuild a matched branch as its schema struct; when that result reaches an allOf merge, Enum.reduce/3 over the struct raised Protocol.UndefinedError and killed the whole cast. Demoting at the merge keeps struct building intact everywhere else (v3.18.2 deliberately strengthened it), and also keeps the anyOf accumulator safe should its struct short-circuit ever change.

Regression test: an allOf wrapper around a oneOf member whose branch casts to a struct — the exact wrapper idiom used to attach a description or default to a referenced union. Before the fix it raises Protocol.UndefinedError; with it, the cast returns the merged map.

Full test suite: 9 doctests, 390 tests, 0 failures.

🤖 Generated with Claude Code

Cast.AllOf merges member results with Utils.merge_maps. A oneOf or
discriminator member rebuilds the matched branch as a struct, and
reducing over a struct raises Protocol.UndefinedError, so any allOf
wrapper around a struct-building union crashes the whole cast.
merge_maps now demotes struct arguments to plain maps first; this also
keeps the anyOf accumulator safe should its struct short-circuit change.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cast.AllOf raises Protocol.UndefinedError when a member schema casts to a struct

1 participant